<html>
<head><meta charset="utf-8"><title>pr-51612-suggest-&amp;mut · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html">pr-51612-suggest-&amp;mut</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="129232539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129232539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129232539">(Jul 06 2018 at 23:56)</a>:</h4>
<p>(obligatory note: let me know if I'm doing this wrong or if I should ask somewhere else.) (also I know it's Friday evening. there's no hurry.)</p>



<a name="129232630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129232630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129232630">(Jul 06 2018 at 23:59)</a>:</h4>
<p>so I'm hacking on librustc_mir/borrow_check, and I'm having trouble telling the difference between an auto-deref binding and a literal <code>ref</code>/<code>ref mut</code> binding.</p>



<a name="129232695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129232695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129232695">(Jul 07 2018 at 00:00)</a>:</h4>
<p>I found BindingMode::BindByReference but it seems to apply to both. in theory I could check if the source span starts with "ref" followed by Pattern_Whitespace or whatever it's called, but that feels kinda hacky.</p>



<a name="129237301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129237301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129237301">(Jul 07 2018 at 02:14)</a>:</h4>
<p>actually I think this is almost exactly the same question I asked in the PR itself (and got an answer to). oopsie.</p>



<a name="129253504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253504">(Jul 07 2018 at 11:23)</a>:</h4>
<p>by "auto-deref binding" do you mean something like the default ref that occurs here <code>match &amp;foo { Some(x) =&gt; .. }</code>?</p>



<a name="129253508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253508">(Jul 07 2018 at 11:23)</a>:</h4>
<p>in the past, we have sometimes extended the data structures to carry more information about what kind of "syntactic sugar" was used</p>



<a name="129253509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253509">(Jul 07 2018 at 11:23)</a>:</h4>
<p>so e.g. you imagine extending <code>BindingMode</code> to indicate whether this <code>ref</code> was explicit or added by us</p>



<a name="129253562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253562">(Jul 07 2018 at 11:25)</a>:</h4>
<p>I also think span-hacking .. isn't the worst thing ever, if it's simple to do, but I agree it's on the hack-y side.</p>



<a name="129253610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253610">(Jul 07 2018 at 11:26)</a>:</h4>
<p>(in the <em>HIR</em> at least the explicit binding mode vs actual binding mode distinction is visible...)</p>



<a name="129253661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129253661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129253661">(Jul 07 2018 at 11:28)</a>:</h4>
<p>I think what we <em>could</em> try to do is to thread the HIR's <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/enum.BindingAnnotation.html" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/enum.BindingAnnotation.html"><code>BindingAnnotation</code></a> information into the MIR, but I'd have to look at how easy/hard that would be</p>



<a name="129265023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129265023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129265023">(Jul 07 2018 at 17:15)</a>:</h4>
<p>hmm. sounds like it's not worth the effort unless we need it in lots of places.</p>



<a name="129269468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129269468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129269468">(Jul 07 2018 at 19:30)</a>:</h4>
<p>yeah, my impression is it's not worth it right now, but it might be worth taking a look later to try as a cleanup</p>



<a name="129337170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129337170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129337170">(Jul 09 2018 at 09:21)</a>:</h4>
<p>hi <span class="user-mention" data-user-id="120442">@ashtneoi</span> I am back from my leave of absence and had started last week looking at rebasing this PR. It sounds like you're close to getting something working though?</p>



<a name="129337830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129337830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129337830">(Jul 09 2018 at 09:36)</a>:</h4>
<p>(I think I just now actually got it working on my end; I ended up going with span inspection and snippet rewriting, the same way your original PR did.)</p>



<a name="129337907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129337907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129337907">(Jul 09 2018 at 09:38)</a>:</h4>
<p>but ... ah, maybe span/snippet inspection will not suffice, due to the hidden <code>&amp;</code>-borrows injected by two-phase borrows. :(</p>



<a name="129337919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129337919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129337919">(Jul 09 2018 at 09:39)</a>:</h4>
<p>In particular, whatever solution we devise, we need to make sure we do not break src/test/ui/issue-27282-reborrow-ref-mut-in-guard.rs</p>



<a name="129337998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129337998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129337998">(Jul 09 2018 at 09:40)</a>:</h4>
<p>(where "breaking the test" here means erroneously suggesting to the user that they use <code>ref mut mut</code>)</p>



<a name="129339096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339096">(Jul 09 2018 at 10:06)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> as far as I know, I'm almost done with what I was trying to do. no guarantees it passes that test you mentioned though.</p>



<a name="129339129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339129">(Jul 09 2018 at 10:06)</a>:</h4>
<p>I was working as if this were just a rebase, but I ended up trashing my original code, so I guess I should just push what I have so far and worry about squashing later.</p>



<a name="129339153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339153">(Jul 09 2018 at 10:07)</a>:</h4>
<p>yeah the code changed a lot and i found it was easier to start from scratch (while looking at the previous PR for inspiration) rather than attempt a true rebase</p>



<a name="129339157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339157">(Jul 09 2018 at 10:07)</a>:</h4>
<p>yep, same</p>



<a name="129339158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339158">(Jul 09 2018 at 10:07)</a>:</h4>
<p>One "obvious" way to compensate for the particular case of <a href="http://issue-27282-reborrow-ref-mut-in-guard.rs" target="_blank" title="http://issue-27282-reborrow-ref-mut-in-guard.rs">issue-27282-reborrow-ref-mut-in-guard.rs</a> would be to also detect if we started with <code>ref mut</code> and bail on making a suggestion in that case. But I'm a little wary of that approach</p>



<a name="129339261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339261">(Jul 09 2018 at 10:09)</a>:</h4>
<p>(and I'm independently planning to revise at least part of the code in src/librustc_mir/build/matches/mod.rs to try to fix <a href="https://github.com/rust-lang/rust/issues/51348" target="_blank" title="https://github.com/rust-lang/rust/issues/51348">https://github.com/rust-lang/rust/issues/51348</a> )</p>



<a name="129339838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129339838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129339838">(Jul 09 2018 at 10:20)</a>:</h4>
<p>hmm, sounds like things are a lot more complicated than I expected when I opened the original PR. we'll see where I get tomorrow, but I might not have the rustc knowledge to figure this out.</p>



<a name="129340715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129340715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129340715">(Jul 09 2018 at 10:39)</a>:</h4>
<p>the simplest thing might be to just restrict the scope of your PR to <em>just</em> fix the suggestion that replaces <code>&amp;</code> with <code>&amp;mut</code></p>



<a name="129340727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129340727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129340727">(Jul 09 2018 at 10:39)</a>:</h4>
<p>and leave the more general case for later work.</p>



<a name="129341301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-%26mut/near/129341301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ashtneoi <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-51612-suggest-.26mut.html#129341301">(Jul 09 2018 at 10:50)</a>:</h4>
<p>ah, that sounds like a good idea</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>